﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Microsoft.Phone.Controls;
// using Microsoft.Phone.Navigation;
using System.Windows.Navigation;
using WP7Square.Helpers;
using WP7Square.ViewModels;
using WP7Square.Classes;
using Touchality.FoursquareApi;
using System.Windows.Media.Imaging;
using Location = WP7Square.Classes.Location;

namespace WP7Square
{
    public partial class Tips : PhoneApplicationPage
    {
        private Location _location;        

       
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Foursquare.GetTips(GetTipsCallback, _location.Latitude, _location.Longitude);
            base.OnNavigatedTo(e);
        }



        private void TipsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //Set datacontext of details page to selected listbox item
            var _root = Application.Current.RootVisual as PhoneApplicationFrame;
            var tran = (TransitioningContentControl)VisualTreeHelper.GetChild(_root, 0);
            tran.Transition = "SlideLeft";
            TipViewModel tipViewModel = TipsList.SelectedItem as TipViewModel;
            if (tipViewModel == null)
            {
                return;
            }
            NavigationService.Navigate(new Uri("/TipDetail.xaml?id=" + tipViewModel.Id, UriKind.RelativeOrAbsolute));
        }


        private void GetTipsCallback(GetTipsCompletedEventArgs e)
        {            

            var viewModel = new NearbyTipsViewModel(e.Result);
            DataContext = viewModel; 
        }


        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {            
            var root = Application.Current.RootVisual as PhoneApplicationFrame;
            var tran = (TransitioningContentControl)VisualTreeHelper.GetChild(root, 0);
            tran.Transition = "SlideRight";
            base.OnBackKeyPress(e);
        }

        private void ApplicationBarAdd_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Come back soon!", "Not implemented", MessageBoxButton.OK);
        }

        private void ApplicationBarRefresh_Click(object sender, EventArgs e)
        {
        }

        private void ApplicationBarBadge_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Come back soon!", "Not implemented", MessageBoxButton.OK);
        }

   
    }
}